package com.kelp.codetoolkit.ui.form


import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.DialogWrapper
import com.intellij.ui.JBColor.border
import java.awt.BorderLayout
import java.awt.GridLayout
import javax.swing.BorderFactory
import javax.swing.JCheckBox
import javax.swing.JComponent
import javax.swing.JLabel
import javax.swing.JPanel
import javax.swing.JScrollPane
import javax.swing.JTextArea

/**
 * @author: liuyuebai
 * @date: 2025/8/6 18:05
 * @description:
 */
class MethodGenerationDialog(project: Project) : DialogWrapper(project)  {

    var methodComment: String = ""
    var writeMapper: Boolean = false
    private val commentTextArea = JTextArea(5, 40).apply {
        lineWrap = true
        wrapStyleWord = true
    }
    private val writeMapperCheckbox = JCheckBox("write dao")

    init {
        title = "Method Generation"
        init()
    }

    override fun createCenterPanel(): JComponent? {
        return JPanel(BorderLayout(10, 10)).apply {
            // method commend：输入框模式区域
            add(JPanel(BorderLayout()).apply {
                add(JLabel("Method comment："), BorderLayout.NORTH)
                // 去掉标题边框，直接添加输入框滚动面板
                add(JScrollPane(commentTextArea), BorderLayout.CENTER)
            }, BorderLayout.NORTH)

            add(JPanel(BorderLayout()).apply {
                add(JLabel("Generate Options："), BorderLayout.WEST)
                add(JPanel(GridLayout(1, 2, 10, 0)).apply {  // 水平并排排列
                    add(writeMapperCheckbox)
                }, BorderLayout.CENTER)
            }, BorderLayout.CENTER)
        }
    }

    override fun doOKAction() {
        // 保存用户输入
        methodComment = commentTextArea.text
        writeMapper = writeMapperCheckbox.isSelected
        super.doOKAction()
    }
}